/**
 * Created by feimao on 15-12-4.
 */
app.controller('showListCtrl',function($scope,$location){
    $scope.names=['赵大','钱二','张三','李四','王五','赵六'];
    $scope.list=JSON.parse(localStorage.list);
    $scope.num=get_num($scope);
    $scope.NOlist_names=get_NOlist_names($scope);
    $scope.total=get_total($scope);
    $scope.goToUrl=function(path){
        $location.path(path);
    };
});
function get_num($scope){
    var list=$scope.list;
    var num=0;
    var obj={};
    list.forEach(function(value){
        if(obj[value.name]==undefined){
            obj[value.name]=1;
            num++;
        }
    });
    return num;
}
function get_NOlist_names($scope){
    var NOlist_names=[];
    var names=$scope.names;
    var list=$scope.list;
    var obj={};
    list.forEach(function(value){
        if(obj[value.name]==undefined){
            obj[value.name]=1;
        }
    });
    names.forEach(function(name){
        if(obj[name]==undefined){
            NOlist_names.push(name);
        }
    });
    return NOlist_names;
}
function get_total($scope){
    var total=0;
    var list=$scope.list;
    list.forEach(function(value){
        total+=Number(value.price);
    });
    return total.toFixed(2);
}